package com.medicalfee.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.medicalfee.dao.ReimbursementList;
import com.medicalfee.dao.ReimbursementListDAO;

public class UpdateReimbursementsController implements Controller {
	private ReimbursementListDAO reimbursementListDao;

	public void setReimbursementListDao(
			ReimbursementListDAO reimbursementListDao) {
		this.reimbursementListDao = reimbursementListDao;
	}

	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		String data = request.getParameter("data");
		JSONObject json = JSONObject.fromObject(data);
		ReimbursementList reimbursement = (ReimbursementList) JSONObject
				.toBean(json);
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		reimbursement.setDate(format.parse(request.getParameter("date")));
		reimbursement.setStartDate(format.parse(request
				.getParameter("startDate")));
		reimbursement.setEndDate(format.parse(request.getParameter("endDate")));
		reimbursementListDao.updateReimbursement(reimbursement);
		return null;
	}

}
